package com.wangp.safeCommit.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wangp.safeCommit.dto.DicItemQueryResponseDTO;
import com.wangp.safeCommit.entity.TbBcDicItemEntity;
import com.wangp.safeCommit.mapper.TbBcDicItemMapper;
import com.wangp.safeCommit.service.ITbBcDicItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 字典项目 服务实现类
 * </p>
 *
 * @author zhangliang
 * @since 2024-12-17
 */
@Service
public class TbBcDicItemServiceImpl extends ServiceImpl<TbBcDicItemMapper, TbBcDicItemEntity> implements ITbBcDicItemService {


    @Autowired
    private TbBcDicItemMapper dicMapper;

    @Override
    public  List<DicItemQueryResponseDTO> getDicItemList(String dicCode) {
        List<TbBcDicItemEntity> dicEntityList= dicMapper.getDicList(dicCode);
        return convertToHazardRespVOList(dicEntityList);
    }

//转换类
    private List<DicItemQueryResponseDTO> convertToHazardRespVOList(List<TbBcDicItemEntity> dicEntities)
         {
        List<DicItemQueryResponseDTO> dicItemDTOList = new ArrayList<>();

        for (TbBcDicItemEntity entity : dicEntities) {
            DicItemQueryResponseDTO dicItemQueryResponseDTO = new DicItemQueryResponseDTO();
            dicItemQueryResponseDTO.setItemName(entity.getItemName());
            dicItemQueryResponseDTO.setItemCode(entity.getItemCode());
            dicItemDTOList.add(dicItemQueryResponseDTO);
        }
        return dicItemDTOList;
    }

}
